<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>w32api 范例</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="w32api.examples.html">范例</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="ref.w32api.html">W32api 函数</a></div>
 <div class="up"><a href="w32api.examples.html">范例</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="w32api.examples-uptime" class="section">
  <h2 class="title">w32api 范例</h2>
  <p class="para">
   本范例获取了系统的运行时间，并且显示在一个消息框里。
  </p>
  <div class="example" id="example-5265">
   <p><strong>Example #1 获取 uptime 并且显示在一个消息框里</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;Define&nbsp;constants&nbsp;needed,&nbsp;taken&nbsp;from<br />//&nbsp;Visual&nbsp;Studio/Tools/Winapi/WIN32API.txt<br /></span><span style="color: #0000BB">define</span><span style="color: #007700">(</span><span style="color: #DD0000">"MB_OK"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Load&nbsp;the&nbsp;extension&nbsp;in<br /></span><span style="color: #0000BB">dl</span><span style="color: #007700">(</span><span style="color: #DD0000">"php_w32api.dll"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Register&nbsp;the&nbsp;GetTickCount&nbsp;function&nbsp;from&nbsp;kernel32.dll<br /></span><span style="color: #0000BB">w32api_register_function</span><span style="color: #007700">(</span><span style="color: #DD0000">"kernel32.dll"</span><span style="color: #007700">,&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"GetTickCount"</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"long"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /></span><span style="color: #FF8000">//&nbsp;Register&nbsp;the&nbsp;MessageBoxA&nbsp;function&nbsp;from&nbsp;User32.dll<br /></span><span style="color: #0000BB">w32api_register_function</span><span style="color: #007700">(</span><span style="color: #DD0000">"User32.dll"</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"MessageBoxA"</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"long"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Get&nbsp;uptime&nbsp;information<br /></span><span style="color: #0000BB">$ticks&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">GetTickCount</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">//&nbsp;Convert&nbsp;it&nbsp;to&nbsp;a&nbsp;nicely&nbsp;displayable&nbsp;text<br /></span><span style="color: #0000BB">$secs&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">floor</span><span style="color: #007700">(</span><span style="color: #0000BB">$ticks&nbsp;</span><span style="color: #007700">/&nbsp;</span><span style="color: #0000BB">1000</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$mins&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">floor</span><span style="color: #007700">(</span><span style="color: #0000BB">$secs&nbsp;</span><span style="color: #007700">/&nbsp;</span><span style="color: #0000BB">60</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$hours&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">floor</span><span style="color: #007700">(</span><span style="color: #0000BB">$mins&nbsp;</span><span style="color: #007700">/&nbsp;</span><span style="color: #0000BB">60</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$str&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">sprintf</span><span style="color: #007700">(</span><span style="color: #DD0000">"You&nbsp;have&nbsp;been&nbsp;using&nbsp;your&nbsp;computer&nbsp;for:"&nbsp;</span><span style="color: #007700">.<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"\r\n&nbsp;%d&nbsp;Milliseconds,&nbsp;or&nbsp;\r\n&nbsp;%d&nbsp;Seconds"&nbsp;</span><span style="color: #007700">.<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"or&nbsp;\r\n&nbsp;%d&nbsp;mins&nbsp;or\r\n&nbsp;%d&nbsp;hours&nbsp;%d&nbsp;mins."</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$ticks</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$secs</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$mins</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$hours</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$mins&nbsp;</span><span style="color: #007700">-&nbsp;(</span><span style="color: #0000BB">$hours</span><span style="color: #007700">*</span><span style="color: #0000BB">60</span><span style="color: #007700">));<br /><br /></span><span style="color: #FF8000">//&nbsp;Display&nbsp;a&nbsp;message&nbsp;box&nbsp;with&nbsp;only&nbsp;an&nbsp;OK&nbsp;button&nbsp;and&nbsp;the&nbsp;uptime&nbsp;text<br /></span><span style="color: #0000BB">MessageBoxA</span><span style="color: #007700">(</span><span style="color: #0000BB">NULL</span><span style="color: #007700">,&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$str</span><span style="color: #007700">,&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"Uptime&nbsp;Information"</span><span style="color: #007700">,&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">MB_OK</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>
 </div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="w32api.examples.html">范例</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="ref.w32api.html">W32api 函数</a></div>
 <div class="up"><a href="w32api.examples.html">范例</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
